//
//  Command.m
//  ImageAnimation
//
//  Created by apple on 5/11/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MovingCommand.h"
#import "FixFrame.h"

@interface MovingCommand()

@property (nonatomic,retain) NSMutableArray *movingDiectionsArray;
@end  

@implementation MovingCommand
@synthesize movingDiectionsArray=_movingDiectionsArray;
- (id)init{
    self = [super init];
    if (self) {
        _movingDiectionsArray = [NSMutableArray array];   
    }
    return self;
}

- (void)addDirection:(MovingDirection)movingDirection{
    NSNumber *num = [NSNumber numberWithInt:movingDirection];
    [self.movingDiectionsArray addObject:num];
}

- (BOOL)canMoveToPreiousDriection{
    return self.movingDiectionsArray.count > 0;
}

- (MovingDirection)getNextDirection{
    MovingDirection movingDriection = rand()%4;
    return movingDriection;
}

- (MovingDirection)getPreviousDirection{
    if (self.movingDiectionsArray.count == 0) {
        return -1;
    }
    
    NSNumber *num = [self.movingDiectionsArray lastObject];
    [self.movingDiectionsArray removeLastObject];
    MovingDirection movingDriection = [num intValue] > 1 ? [num intValue]-2:[num intValue]+2;
    
    return movingDriection;
}

- (void)clearMovingCommand{
    self.movingDiectionsArray = [NSMutableArray array];
}
@end
